define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'lejia/weixinfensi/index' + location.search,
                    add_url: 'lejia/weixinfensi/add',
                    edit_url: 'lejia/weixinfensi/edit',
                    del_url: 'lejia/weixinfensi/del',
                    multi_url: 'lejia/weixinfensi/multi',
                    table: 'wx_config',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'wechat_id',
                sortName: 'nums',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'wx_name', title: __('Wx_name')},
                        {field: 'principal_name', title: __('Principal_name')},
                        {field: 'ctime', title:'创建时间', operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate:false},
                        {field: 'exp_time', title: '过期时间', operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate:false},
                        {field: 'type', title: __('type'),operate:false},
                        {field: 'nums', title: '吸粉数',operate:false,sort:true},
                        {field: 'issub', title: '关注人数',operate:false},
                        {field: 'lasttime', title: '最后使用时间',operate:false},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            Form.events.datetimepicker($("#cstarttime"));
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});